#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void *PrintChar(void *para)
{
    char* stringpara;
    
    stringpara = (char*) para;
    printf("The string para is: %s\n", stringpara);
    pthread_exit(NULL);
}

void *PrintInt(void *para)
{
    long* intpara;
    intpara = (long*) para;
    printf("The int para is %ld.\n", *intpara);
    pthread_exit(NULL);
}


int main(int argc, char *argv[]) {
    pthread_t thread1;
    pthread_t thread2;
    pthread_attr_t attr;
    int rc;
    long t;
    void *status;
    long intpara=36;	//type int parameter
    char stringpara[]="Hello again to you!";	//type char* parameter
    

    /* Initialize and set thread detached attribute */
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    printf("Main: creating thread1\n");
        rc = pthread_create(&thread1, &attr, PrintInt, (void *) &intpara);
        if (rc) {
            printf("ERROR; return code from pthread_create() is % d\n", rc);
            exit(-1);
        }
    printf("Main: creating thread2\n");
        rc = pthread_create(&thread2, &attr, PrintChar, (void *) stringpara);
        if (rc) {
            printf("ERROR; return code from pthread_create() is % d\n", rc);
            exit(-1);
        }

    /* Free attribute and wait for the other threads 
    pthread_attr_destroy(&attr);
    rc = pthread_join(thread1, &status);
        if (rc) {
            printf("ERROR; return code from pthread_join() is % d\n", rc);
            exit(-1);
        }
        printf("Main: completed join with thread1 having a status of % ld\n", (long) status);
   
        pthread_attr_destroy(&attr);
    rc = pthread_join(thread2, &status);
        if (rc) {
            printf("ERROR; return code from pthread_join() is % d\n", rc);
            exit(-1);
        }
        printf("Main: completed join with thread2 having a status of % ld\n", (long) status);
    
*/
    printf("Main: program completed. Exiting.\n");
    pthread_exit(NULL);
}
